<template>
  <div>
    <div v-wechat-title="$route.meta.title"></div>
    <el-container>
      <el-header>
        <div>
          Vue Project Demo
          <el-button class="logoutbtn" type="info" @click="logout">
            退出
          </el-button>
        </div>
      </el-header>
      <el-container>
        <el-aside width="200px">
          <div>
            <el-menu :default-active="activepath" class="el-menu-vertical-demo">
              <el-menu-item index="1" @click="saveNavState('1', '/welcome')">
                <i class="el-icon-menu"></i>
                <span slot="title">首页</span>
              </el-menu-item>
              <el-submenu index="2">
                <template slot="title">
                  <i class="el-icon-user"></i>
                  <span>用户</span>
                </template>
                <el-menu-item-group>
                  <template slot="title">分组</template>
                  <el-menu-item
                    index="2-1"
                    @click="saveNavState('2-1', '/employee')"
                    >用户列表</el-menu-item
                  >
                  <el-menu-item
                    index="2-2"
                    @click="saveNavState('2-2', '/adminlist')"
                    >管理列表</el-menu-item
                  >
                </el-menu-item-group>
              </el-submenu>
              <el-submenu index="3">
                <template slot="title">
                  <i class="el-icon-thumb"></i>
                  <span>权限</span>
                </template>
                <el-menu-item-group>
                  <template slot="title">分组</template>
                  <el-menu-item
                    index="3-1"
                    @click="saveNavState('3-1', '/rolelist')"
                    >角色管理</el-menu-item
                  >
                </el-menu-item-group>
              </el-submenu>
              <el-menu-item index="4" @click="saveNavState('4', '/words')">
                <i class="el-icon-menu"></i>
                <span slot="title">壹言</span>
              </el-menu-item>
            </el-menu>
          </div>
        </el-aside>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  data() {
    return {
      activepath: "",
    };
  },
  created() {
    this.activepath = window.sessionStorage.getItem("activepath");
  },
  methods: {
    logout() {
      window.sessionStorage.clear();
      this.$Message.success("退出成功！");
      this.$router.push("/login");
    },
    // 保存连接激活状态
    saveNavState(activepath, url) {
      window.sessionStorage.setItem("activepath", activepath);
      this.activepath = activepath;
      this.$router.push(url);
    },
  },
};
</script>

<style scoped>
.el-container {
  height: 700px;
}
.el-header,
.el-footer {
  background-color: rgb(171, 176, 247);
  color: #333;
  text-align: center;
  line-height: 60px;
}

.el-aside {
  background-color: white;
  color: #333;
  text-align: center;
  line-height: 200px;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  text-align: center;
  line-height: 30px;
  height: 100 vh;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}

.logoutbtn {
  position: absolute;
  right: 30px;
  top: 10px;
}
</style>